package cn.akwangl.future;

import java.util.Random;
import java.util.concurrent.*;

/**
 * Future 简单用法.
 *
 * @author 阿坤同学
 * @date 2022-12-13 10:24
 */
public class SimpleFuture {


    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        OrderNoTask orderNoTask = new OrderNoTask();
        Future<Integer> orderNoFuture = executorService.submit(orderNoTask);

        Integer orderNo;
        try {
            orderNo = orderNoFuture.get();
            System.out.println(orderNo);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        executorService.shutdown();
    }

    static class OrderNoTask implements Callable<Integer> {
        public static final Random random = new Random();

        @Override
        public Integer call() throws Exception {
            return random.nextInt();
        }
    }
}
